(function() {
  var body_dropdown_items, check_precheck, do_input_1, do_input_3, express, fs, iced, input_precheck, jobs, mkdirp, mmm, moment, multer, pgsql, router, uploader, uuid, __iced_k, __iced_k_noop;

  iced = require('iced-runtime');
  __iced_k = __iced_k_noop = function() {};

  express = require('express');

  pgsql = require('pg');

  uuid = require('uuid');

  moment = require('moment');

  fs = require('fs');

  multer = require('multer');

  mmm = require('mmmagic');

  mkdirp = require('mkdirp');

  jobs = require('../lib/merch_jobs');

  router = express.Router();

  module.exports = router;

  router.use(function(req, res, next) {
    var k, _i, _len, _ref;
    _ref = ['t20_fee', 'trctl', 'settl_merid', 'mapto_merid', 'unit_license_exp', 'input_time', 'check_time', 'effect_time'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k] || req.body[k].length === 0) {
        req.body[k] = null;
      }
    }
    return next();
  });

  router.all('/', function(req, res, next) {
    var client, done, err, ex_count, result, ret_records, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    where_clause = "( m.serial::text like $1 or m.uuid like $1 or m.merno like $1 or m.name like $1 or m.contact like $1 or m.telephone like $1 or m.mobile like $1 or m.fax like $1 or m.email like $1 or m.address like $1 or m.unit_name like $1 or m.unit_code like $1 or m.unit_license like $1 or m.unit_tax_code like $1 or m.unit_address like $1 or m.unit_legal_name like $1 or m.unit_cred_no like $1 )";
    if (req.body.inside && req.body.inside.length > 0) {
      where_clause += " and m.inside::boolean = " + (req.body.inside === 'true');
      res.locals.inside = req.body.inside;
    }
    if (req.body.chnl && req.body.chnl.length > 0) {
      where_clause += " and m.chnl::int = " + req.body.chnl;
      res.locals.chnl = req.body.chnl;
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 48
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select count(m.*)::int as count from pay_merch as m where " + where_clause + " and m.shaded = false", ['%' + res.locals.keyword + '%'], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 56
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.total = result.rows[0].count;
          ex_count = 0;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select count(m.*)::int as count from pay_merch_ex as m where " + where_clause + " and m.inputer = $2", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 69
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            ex_count += result.rows[0].count;
            (function(__iced_k) {
              if (res.locals.page_perms.check) {
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                  });
                  client.query("select count(m.*)::int as count from pay_merch_ex as m where " + where_clause + " and m.inputer <> $2 and m.checked = false and m.rejected = false", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid], __iced_deferrals.defer({
                    assign_fn: (function() {
                      return function() {
                        err = arguments[0];
                        return result = arguments[1];
                      };
                    })(),
                    lineno: 81
                  }));
                  __iced_deferrals._fulfill();
                })(function() {
                  if (err) {
                    done(client);
                    return next(err);
                  }
                  return __iced_k(ex_count += result.rows[0].count);
                });
              } else {
                return __iced_k();
              }
            })(function() {
              (function(__iced_k) {
                if (res.locals.page_perms.check) {
                  (function(__iced_k) {
                    __iced_deferrals = new iced.Deferrals(__iced_k, {
                      parent: ___iced_passed_deferral,
                      filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                    });
                    client.query("select count(m.*)::int as count from pay_merch_ex as m where " + where_clause + " and m.checker = $2 and m.checked = true", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid], __iced_deferrals.defer({
                      assign_fn: (function() {
                        return function() {
                          err = arguments[0];
                          return result = arguments[1];
                        };
                      })(),
                      lineno: 93
                    }));
                    __iced_deferrals._fulfill();
                  })(function() {
                    if (err) {
                      done(client);
                      return next(err);
                    }
                    return __iced_k(ex_count += parseInt(result.rows[0].count));
                  });
                } else {
                  return __iced_k();
                }
              })(function() {
                res.locals.total += ex_count;
                ret_records = [];
                (function(__iced_k) {
                  if (res.locals.offset === 0 && res.locals.page_perms.check) {
                    (function(__iced_k) {
                      __iced_deferrals = new iced.Deferrals(__iced_k, {
                        parent: ___iced_passed_deferral,
                        filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                      });
                      client.query("select m.*, u.realname as input_user, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes, true as ex from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee where " + where_clause + " and m.inputer <> $2 and m.checked = false and m.rejected = false order by m.serial desc limit $3::int", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid, res.locals.page_rows - ret_records.length], __iced_deferrals.defer({
                        assign_fn: (function() {
                          return function() {
                            err = arguments[0];
                            return result = arguments[1];
                          };
                        })(),
                        lineno: 119
                      }));
                      __iced_deferrals._fulfill();
                    })(function() {
                      if (err) {
                        done(client);
                        return next(err);
                      }
                      return __iced_k(ret_records.push.apply(ret_records, result.rows));
                    });
                  } else {
                    return __iced_k();
                  }
                })(function() {
                  (function(__iced_k) {
                    if (res.locals.page_perms.check && res.locals.offset === 0 && ret_records.length < res.locals.page_rows) {
                      (function(__iced_k) {
                        __iced_deferrals = new iced.Deferrals(__iced_k, {
                          parent: ___iced_passed_deferral,
                          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                        });
                        client.query("select m.*, u.realname as input_user, u2.realname as check_user, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes, true as ex from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer left join web_users as u2 on u2.uuid = m.checker left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee where " + where_clause + " and m.checker = $2 and m.checked = true order by m.serial desc limit $3::int", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid, res.locals.page_rows - ret_records.length], __iced_deferrals.defer({
                          assign_fn: (function() {
                            return function() {
                              err = arguments[0];
                              return result = arguments[1];
                            };
                          })(),
                          lineno: 145
                        }));
                        __iced_deferrals._fulfill();
                      })(function() {
                        if (err) {
                          done(client);
                          return next(err);
                        }
                        return __iced_k(ret_records.push.apply(ret_records, result.rows));
                      });
                    } else {
                      return __iced_k();
                    }
                  })(function() {
                    (function(__iced_k) {
                      if (res.locals.offset === 0 && ret_records.length < res.locals.page_rows) {
                        (function(__iced_k) {
                          __iced_deferrals = new iced.Deferrals(__iced_k, {
                            parent: ___iced_passed_deferral,
                            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                          });
                          client.query("select m.*, u.realname as input_user, u2.realname as check_user, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes, true as ex from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer left join web_users as u2 on u2.uuid = m.checker left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee where " + where_clause + " and m.inputer = $2 order by m.serial desc limit $3::int", ['%' + res.locals.keyword + '%', req.session.userinfo.uuid, res.locals.page_rows - ret_records.length], __iced_deferrals.defer({
                            assign_fn: (function() {
                              return function() {
                                err = arguments[0];
                                return result = arguments[1];
                              };
                            })(),
                            lineno: 169
                          }));
                          __iced_deferrals._fulfill();
                        })(function() {
                          if (err) {
                            done(client);
                            return next(err);
                          }
                          return __iced_k(ret_records.push.apply(ret_records, result.rows));
                        });
                      } else {
                        return __iced_k();
                      }
                    })(function() {
                      (function(__iced_k) {
                        if (ret_records.length < res.locals.page_rows) {
                          (function(__iced_k) {
                            __iced_deferrals = new iced.Deferrals(__iced_k, {
                              parent: ___iced_passed_deferral,
                              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                            });
                            client.query("select m.*, u.realname as input_user, u2.realname as check_user, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes, count(distinct m4.uuid) + count(distinct m5.uuid) + count(distinct t.uuid) as n_refs, count(t.*) as n_terms from pay_merch as m left join web_users as u on u.uuid = m.inputer left join web_users as u2 on u2.uuid = m.checker left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee left join pay_merch as m4 on ( m4.settl_merid = m.uuid or m4.mapto_merid = m.uuid) left join pay_merch_ex as m5 on ( m5.settl_merid = m.uuid or m5.mapto_merid = m.uuid) left join pay_terms as t on t.merid = m.uuid where " + where_clause + " and m.shaded = false group by m.serial, m.uuid, u.realname, u2.realname, m2.name, m2.merno, m3.name, m3.merno, f1.name, f1.notes order by m.serial desc offset $2::int limit $3::int", ['%' + res.locals.keyword + '%', res.locals.offset === 0 ? 0 : res.locals.offset - ex_count, res.locals.page_rows - ret_records.length], __iced_deferrals.defer({
                              assign_fn: (function() {
                                return function() {
                                  err = arguments[0];
                                  return result = arguments[1];
                                };
                              })(),
                              lineno: 203
                            }));
                            __iced_deferrals._fulfill();
                          })(function() {
                            if (err) {
                              done(client);
                              return next(err);
                            }
                            return __iced_k(ret_records.push.apply(ret_records, result.rows));
                          });
                        } else {
                          return __iced_k();
                        }
                      })(function() {
                        done();
                        return res.render('merch/index', {
                          records: ret_records
                        });
                      });
                    });
                  });
                });
              });
            });
          });
        });
      };
    })(this));
  });

  router.all('/settl', function(req, res, next) {
    var client, done, err, limit_index, offset_index, params, records, result, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '虚拟清算户'
    });
    where_clause = "1 = 1";
    params = [];
    res.locals.settl_merid = req.query.settl_merid;
    if (!res.locals.settl_merid) {
      res.locals.settl_merid = req.body.settl_merid;
    }
    if (res.locals.settl_merid) {
      where_clause += ' and m.settl_merid = $1';
      params.push(res.locals.settl_merid);
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 224
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select count(m.*) as count from pay_merch as m where " + where_clause, params, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 230
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.total = parseInt(result.rows[0].count);
          offset_index = params.length + 1;
          params.push(res.locals.offset);
          limit_index = params.length + 1;
          params.push(res.locals.page_rows);
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select m.* from pay_merch as m where " + where_clause + " order by serial desc offset $" + offset_index + "::int limit $" + limit_index + "::int", params, __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 243
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            records = result.rows;
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("select * from pay_merch where chnl = 0", __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 249
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              res.locals.settl_merids = result.rows;
              done();
              return res.render('merch/settl', {
                records: records
              });
            });
          });
        });
      };
    })(this));
  });

  body_dropdown_items = function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 257
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select uuid, merno, name from pay_merch where inside = true and chnl = 0 and disabled = false and shaded = false", __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 264
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.settl_merids = result.rows;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select * from pay_trctl_t", __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 269
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            res.locals.trctl_list = result.rows;
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("select * from pay_fee", __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 275
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              res.locals.fees = result.rows;
              done();
              return next();
            });
          });
        });
      };
    })(this));
  };

  router.get('/new', body_dropdown_items, function(req, res, next) {
    res.locals.breadcrumbs.push({
      'title': '新增商户'
    });
    return res.render('merch/new', {
      record: {}
    });
  });

  router.post('/new', function(req, res, next) {
    var client, done, err, k, merch_serial, merch_uuid, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    _ref = ['inside', 'chnl', 'merno', 'name'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    req.body.merno = req.body.merno.replace(/\s/g, '');
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 293
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_merch where inside = $1 and chnl = $2 and merno = $3", [req.body.inside, req.body.chnl, req.body.merno], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 300
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length > 0) {
            done();
            return next(new Error('商户 ' + req.body.merno + ' 已存在，请检查'));
          }
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select m.*, u.realname as user from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer where m.inside = $1 and m.chnl = $2 and m.merno = $3 and m.action = 1", [req.body.inside, req.body.chnl, req.body.merno], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 313
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            if (result.rows.length > 0) {
              done();
              return next(new Error('商户' + req.body.merno + ' 已被用户 ' + result.rows[0].user + ' 添加，尚未复核或尚未生效'));
            }
            merch_uuid = uuid.v4();
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("insert into pay_merch ( shaded, uuid, inside, chnl, merno, name, trctl, inputer, checker ) values ( true, $1, $2, $3, $4, $5, $6, $7, $8 ) returning serial", [merch_uuid, req.body.inside === 'true', parseInt(req.body.chnl), req.body.merno, req.body.name, req.body.trctl, req.session.userinfo.uuid, req.session.userinfo.uuid], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 331
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              merch_serial = result.rows[0].serial;
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                });
                client.query("insert into pay_merch_ex ( uuid,              inside,         chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, ref_serial,        ref_uuid, inputer,           input_time,     action ) values ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, CURRENT_TIMESTAMP, 1 )", [uuid.v4(), req.body.inside === 'true', parseInt(req.body.chnl), req.body.merno, req.body.t20_fee, req.body.trctl, req.body.settl_merid, req.body.mapto_merid, req.body.name, req.body.contact, req.body.telephone, req.body.mobile, req.body.fax, req.body.email, req.body.address, req.body.unit_name, req.body.unit_name_abbr, req.body.unit_english, req.body.unit_english_abbr, req.body.unit_code, req.body.unit_license, req.body.unit_license_exp, req.body.unit_tax_code, req.body.unit_issuer, req.body.unit_address, parseInt(req.body.unit_type) || 99, req.body.unit_legal_name, parseInt(req.body.unit_cred_type) || 99, req.body.unit_cred_no, parseInt(req.body.unit_assets) || 0, req.body.unit_scope, req.body.keys, req.body.notes, merch_serial, merch_uuid, req.session.userinfo.uuid], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 375
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                done();
                req.app.set('notify_modified_time', moment().format('x'));
                return res.redirect('/merch');
              });
            });
          });
        });
      };
    })(this));
  });

  router.get('/edit/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '编辑商户信息'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 388
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_merch where serial = $1 or uuid = $2", [parseInt(req.params.id) || 0, req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 394
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error('未查询到商户记录'));
          }
          record = result.rows[0];
          return res.render('merch/edit', {
            record: record
          });
        });
      };
    })(this));
  });

  router.post('/edit', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    _ref = ['serial', 'uuid', 'inside', 'chnl', 'merno', 'name'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    req.body.merno = req.body.merno.replace(/\s/g, '');
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 412
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select m.*, u.realname as input_user from pay_merch_ex as m left join web_users as u on m.inputer = u.uuid where m.ref_uuid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 421
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length > 0) {
            done();
            return next(new Error("该记录被用户 [" + result.rows[0].input_user + "] 修改后尚未生效，在新信息生效前不允许再次修改"));
          }
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("insert into pay_merch_ex ( uuid,              inside,         chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, ref_serial,        ref_uuid, inputer,           input_time,     action ) values ( $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, CURRENT_TIMESTAMP, 2 )", [uuid.v4(), req.body.inside === 'true', req.body.chnl, req.body.merno, req.body.t20_fee, req.body.trctl, req.body.settl_merid, req.body.mapto_merid, req.body.name, req.body.contact, req.body.telephone, req.body.mobile, req.body.fax, req.body.email, req.body.address, req.body.unit_name, req.body.unit_name_abbr, req.body.unit_english, req.body.unit_english_abbr, req.body.unit_code, req.body.unit_license, req.body.unit_license_exp, req.body.unit_tax_code, req.body.unit_issuer, req.body.unit_address, req.body.unit_type, req.body.unit_legal_name, parseInt(req.body.unit_cred_type) || 99, req.body.unit_cred_no, parseInt(req.body.unit_assets) || 0, req.body.unit_scope, req.body.keys, req.body.notes, req.body.serial, req.body.uuid, req.session.userinfo.uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 467
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            done();
            req.app.set('notify_modified_time', moment().format('x'));
            return res.redirect('/merch');
          });
        });
      };
    })(this));
  });

  router.post('/disable', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['serial', 'uuid', 'disabled'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 481
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch set disabled = $1 where serial = $2 and uuid = $3", [req.body.disabled, req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 487
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          return res.json({
            succ: true,
            redirect: '/merch'
          });
        });
      };
    })(this));
  });

  router.post('/delete', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['serial', 'uuid'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 498
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_merch where settl_merid = $1 or mapto_merid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 505
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length > 0) {
            done();
            return next(new Error("该记录正被商户 [" + result.rows[0].merno + "] 引用，在解除引用关系之前不允许删除"));
          }
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select m.*, u.realname as input_user from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer where m.ref_uuid = $1", [req.body.uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 519
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            if (result.rows.length > 0) {
              done();
              return next(new Error("该记录被用户 [" + result.rows[0].input_user + "] 修改后尚未生效，在新信息生效前不允许删除"));
            }
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("select * from pay_merch_ex where settl_merid = $1 or mapto_merid = $1", [req.body.uuid], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 531
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              if (result.rows.length > 0) {
                done();
                return next(new Error("该记录正被待复核的商户 [" + result.rows[0].merno + "] 引用，在解除引用关系之前不允许删除"));
              }
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                });
                client.query("insert into pay_merch_ex ( uuid,              inside,         chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, ref_serial,        ref_uuid, inputer,           input_time,     action ) ( select $1,                inside,         chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, serial,            uuid, $2,                CURRENT_TIMESTAMP, 3 from pay_merch where uuid = $3 )", [uuid.v4(), req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 565
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                done();
                req.app.set('notify_modified_time', moment().format('x'));
                return res.json({
                  succ: true,
                  redirect: '/merch'
                });
              });
            });
          });
        });
      };
    })(this));
  });

  router.get('/input/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '修改商户信息'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 577
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select m.*, u.realname as check_user from pay_merch_ex as m left join web_users as u on u.uuid = m.checker where (m.serial = $1 or m.uuid = $2) and m.inputer = $3", [parseInt(req.params.id) || 0, req.params.id, req.session.userinfo.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 587
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error('未查询到商户记录，可能已经被复核并生效了.'));
          }
          record = result.rows[0];
          if (record.checked) {
            return next(new Error("该记录已被``" + record.check_user + "''复核，不允许继续修改"));
          }
          return res.render('merch/input', {
            record: record
          });
        });
      };
    })(this));
  });

  router.post('/input/delete', function(req, res, next) {
    var client, done, err, k, remove_record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['serial', 'uuid'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 607
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_merch_ex where checked = false and inputer = $1 and serial = $2 and uuid = $3", [req.session.userinfo.uuid, req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 614
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length === 0) {
            done();
            return next(new Error('未查询到待删除记录，可能已被删除.'));
          }
          remove_record = result.rows[0];
          client.query('begin');
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("delete from pay_merch_ex where checked = false and inputer = $1 and serial = $2 and uuid = $3", [req.session.userinfo.uuid, req.body.serial, req.body.uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 627
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            (function(__iced_k) {
              if (remove_record.action === 1) {
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                  });
                  client.query("delete from pay_merch where shaded = true and uuid = $1", [remove_record.ref_uuid], __iced_deferrals.defer({
                    assign_fn: (function() {
                      return function() {
                        err = arguments[0];
                        return result = arguments[1];
                      };
                    })(),
                    lineno: 635
                  }));
                  __iced_deferrals._fulfill();
                })(function() {
                  if (err) {
                    done(client);
                    return next(err);
                  }
                  return __iced_k();
                });
              } else {
                return __iced_k();
              }
            })(function() {
              client.query('commit');
              done();
              req.app.set('notify_modified_time', moment().format('x'));
              return res.json({
                succ: true,
                redirect: '/merch'
              });
            });
          });
        });
      };
    })(this));
  });

  input_precheck = function(req, res, next) {
    var client, done, err, k, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    _ref = ['serial', 'uuid', 'inside', 'chnl', 'merno', 'name'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 650
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select m.checked, u.realname as check_user from pay_merch_ex as m left join web_users as u on u.uuid = m.checker where m.serial = $1 and m.uuid = $2", [req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 660
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error("未找到商户 " + req.body.uuid + " 的信息，可能已被复核并已生效"));
          }
          record = result.rows[0];
          if (result.rows[0].checked) {
            return next(new Error("该商户信息已被用户 " + record.check_user + " 复核，不允许继续修改"));
          }
          return next();
        });
      };
    })(this));
  };

  do_input_1 = function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 676
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch_ex set inside = $1,             chnl = $2,             merno = $3, trctl = $4,              settl_merid = $5,      mapto_merid = $6, name = $7,               contact = $8,          telephone = $9, mobile = $10,            fax = $11,             email = $12, address = $13, unit_name = $14,         unit_name_abbr = $15,  unit_english = $16, unit_english_abbr = $17, unit_code = $18,       unit_license = $19, unit_license_exp = $20,  unit_tax_code = $21,   unit_issuer = $22, unit_address = $23,      unit_type = $24,       unit_legal_name = $25, unit_cred_type = $26,    unit_cred_no = $27,    unit_assets = $28, unit_scope = $29, keys = $30,              notes = $31, inputer = $32,           input_time = CURRENT_TIMESTAMP, checked = false,         rejected = false,      t20_fee = $33 where serial = $34 and uuid = $35", [req.body.inside === 'true', parseInt(req.body.chnl), req.body.merno, req.body.trctl, req.body.settl_merid, req.body.mapto_merid, req.body.name, req.body.contact, req.body.telephone, req.body.mobile, req.body.fax, req.body.email, req.body.address, req.body.unit_name, req.body.unit_name_abbr, req.body.unit_english, req.body.unit_english_abbr, req.body.unit_code, req.body.unit_license, req.body.unit_license_exp, req.body.unit_tax_code, req.body.unit_issuer, req.body.unit_address, req.body.unit_type, req.body.unit_legal_name, parseInt(req.body.unit_cred_type) || 99, req.body.unit_cred_no, parseInt(req.body.unit_assets) || 0, req.body.unit_scope, req.body.keys, req.body.notes, req.session.userinfo.uuid, req.body.t20_fee, req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 711
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.redirect('/merch');
        });
      };
    })(this));
  };

  do_input_3 = function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 721
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch_ex set inputer = $1,            input_time = CURRENT_TIMESTAMP, checked = false,         rejected = false where serial = $2 and uuid = $3", [req.session.userinfo.uuid, req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 730
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.redirect('/merch');
        });
      };
    })(this));
  };

  router.post('/input/:action', input_precheck, function(req, res, next) {
    req.body.merno = req.body.merno.replace(/\s/g, '');
    switch (parseInt(req.params.action)) {
      case 1:
      case 2:
        return do_input_1(req, res, next);
      case 3:
        return do_input_3(req, res, next);
      default:
        return next(new Error('您访问的功能不存在'));
    }
  });

  router.get('/check/1/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, key, record, result, sql, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '确认新增商户'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 752
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        key = req.params.id.indexOf('-') > 0 ? 'uuid' : 'serial';
        sql = "select m.*, u.realname as input_user, u2.realname as check_user from pay_merch_ex as m left join web_users as u on m.inputer = u.uuid left join web_users as u2 on m.checker = u2.uuid where m." + key + " = $1 and m.inputer <> $2 and action = 1";
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query(sql, [req.params.id, req.session.userinfo.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 763
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error('未找到商户记录'));
          }
          record = result.rows[0];
          return res.render('merch/check1', {
            record: record
          });
        });
      };
    })(this));
  });

  router.get('/check/2/:id', function(req, res, next) {
    var client, done, err, obj, record, result, split_trctl, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '确认变更商户信息'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 776
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select m.*, u.realname as input_user, u2.realname as check_user, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes from pay_merch_ex as m left join web_users as u on m.inputer = u.uuid left join web_users as u2 on m.checker = u2.uuid left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee where (m.serial = $1 or m.uuid = $2) and m.inputer <> $3 and action = 2", [parseInt(req.params.id) || 0, req.params.id, req.session.userinfo.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 794
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length === 0) {
            done();
            return next(new Error('未找到商户记录'));
          }
          record = result.rows[0];
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select m.*, m2.name as settl_mer_name, m2.merno as settl_mer_no, m3.name as mapto_mer_name, m3.merno as mapto_mer_no, f1.name as t20_fee_name, f1.notes as t20_fee_notes from pay_merch as m left join pay_merch as m2 on m.settl_merid = m2.uuid left join pay_merch as m3 on m.mapto_merid = m3.uuid left join pay_fee as f1 on f1.uuid = m.t20_fee where m.uuid = $1", [record.ref_uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 814
            }));
            __iced_deferrals._fulfill();
          })(function() {
            var _i, _len, _ref;
            if (err) {
              done(client);
              return next(err);
            }
            done();
            if (result.rows.length === 0) {
              return next(new Error('未找到原商户记录'));
            }
            res.locals.ref_record = result.rows[0];
            _ref = [record, res.locals.ref_record];
            for (_i = 0, _len = _ref.length; _i < _len; _i++) {
              obj = _ref[_i];
              if (obj.unit_license_exp) {
                obj.unit_license_exp = obj.unit_license_exp.format('YYYY-MM-DD');
              }
            }
            split_trctl = function(record) {
              var code, k, v, _j, _len1, _ref1, _ref2, _results;
              if (!record.trctl) {
                return;
              }
              record.trctl_trcodes = '';
              if (record.trctl.trcodes) {
                _ref1 = record.trctl.trcodes;
                for (k in _ref1) {
                  v = _ref1[k];
                  record.trctl_trcodes += constant.trctl_codes[k];
                  record.trctl_trcodes += '、';
                }
              }
              _ref2 = ['t20', 't60', 'tz0'];
              _results = [];
              for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
                code = _ref2[_j];
                if (!record.trctl["" + code]) {
                  continue;
                }
                record["" + code + "_time"] = (record.trctl["" + code].time_begin || '不限') + ' － ' + (record.trctl["" + code].time_end || '不限');
                record["" + code + "_amt_per"] = (record.trctl["" + code].min_amt_per || '0.0') + ' 元 － ' + (record.trctl["" + code].max_amt_per || '0.0') + ' 元';
                record["" + code + "_max_minute"] = (record.trctl["" + code].max_amt_minute || '0.0') + ' 元 / ' + (record.trctl["" + code].max_cnt_minute || '0') + ' 笔';
                _results.push(record["" + code + "_max_day"] = (record.trctl["" + code].max_amt_day || '0.0') + ' 元 / ' + (record.trctl["" + code].max_amt_day || '0') + ' 笔');
              }
              return _results;
            };
            split_trctl(record);
            split_trctl(res.locals.ref_record);
            return res.render('merch/check2', {
              record: record
            });
          });
        });
      };
    })(this));
  });

  router.get('/check/3/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, key, record, result, sql, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '确认删除商户'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 860
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        key = req.params.id.indexOf('-') > 0 ? 'uuid' : 'serial';
        sql = "select m.*, u.realname as input_user, u2.realname as check_user from pay_merch_ex as m left join web_users as u on m.inputer = u.uuid left join web_users as u2 on m.checker = u2.uuid where m." + key + " = $1 and m.inputer <> $2 and action = 3";
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query(sql, [req.params.id, req.session.userinfo.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 871
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error('未找到商户记录'));
          }
          record = result.rows[0];
          return res.render('merch/check3', {
            record: record
          });
        });
      };
    })(this));
  });

  check_precheck = function(req, res, next) {
    var client, done, err, k, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    _ref = ['serial', 'uuid', 'input_time'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 885
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select m.*, u.realname as input_user, u2.realname as check_user from pay_merch_ex as m left join web_users as u on u.uuid = m.inputer left join web_users as u2 on u2.uuid = m.checker where m.serial = $1 and m.uuid = $2", [req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 895
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (result.rows.length === 0) {
            return next(new Error('未查询到待复核记录，可能已经被其他用户复核并生效了，请检查'));
          }
          record = result.rows[0];
          if (record.checked && record.checker !== req.session.userinfo.uuid) {
            return next(new Error("用户``" + record.check_user + "''已经复核了此记录"));
          }
          if (record.input_time.isAfter(req.body.input_time, 'second')) {
            return next(new Error("在您复核期间，用户``" + record.input_user + "''再次修改了商户信息，请刷新"));
          }
          req.app.set('notify_modified_time', moment().format('x'));
          return next();
        });
      };
    })(this));
  };

  router.post('/check/pass', check_precheck, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    if (!req.body.effect_time || req.body.effect_time.length === 0) {
      return next(new Error('请输入信息生效时间'));
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 924
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select action, inputer, ref_uuid from pay_merch_ex where uuid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 930
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          record = result.rows[0];
          (function(__iced_k) {
            if (record && parseInt(record.action) === 3) {
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                });
                client.query("update pay_merch set checker = $1, inputer = $2 where uuid = $3 and checker <> $4 and inputer <> $5", [req.session.userinfo.uuid, record.inputer, record.ref_uuid, req.session.userinfo.uuid, record.inputer], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 943
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                return __iced_k();
              });
            } else {
              return __iced_k();
            }
          })(function() {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("update pay_merch_ex set checked = true, checker = $1, check_time = CURRENT_TIMESTAMP, effect_time = $2, rejected = false, reject_reason = '' where serial = $3 and uuid = $4", [req.session.userinfo.uuid, req.body.effect_time, req.body.serial, req.body.uuid], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 955
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              done();
              jobs.sched_effect(req.body.uuid, req.body.effect_time);
              return res.redirect('/merch');
            });
          });
        });
      };
    })(this));
  });

  router.post('/check/reject', check_precheck, function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    if (!req.body.reject_reason || req.body.reject_reason.length === 0) {
      return next(new Error('请输入拒绝原因'));
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 968
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch_ex set checked = false, checker = $1, check_time = CURRENT_TIMESTAMP, rejected = true, reject_reason = $2 where serial = $3 and uuid = $4", [req.session.userinfo.uuid, req.body.reject_reason, req.body.serial, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 979
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          return res.redirect('/merch');
        });
      };
    })(this));
  });

  router.post('/batch/check', function(req, res, next) {
    var client, done, err, index, item, k, params, records, result, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['records'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    records = JSON.parse(req.body.records);
    if (records.length === 0) {
      return {
        succ: true,
        redirect: '/merch'
      };
    }
    params = [];
    params.push(req.session.userinfo.uuid);
    where_clause = "uuid in (";
    for (index = _j = 0, _len1 = records.length; _j < _len1; index = ++_j) {
      item = records[index];
      where_clause += "$" + (index + 2);
      if (index < records.length - 1) {
        where_clause += ", ";
      }
      params.push(item.uuid);
    }
    where_clause += ")";
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1005
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch_ex set checked = true, checker = $1, check_time = CURRENT_TIMESTAMP, effect_time = CURRENT_TIMESTAMP, rejected = false, reject_reason = '' where " + where_clause, params, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1012
          }));
          __iced_deferrals._fulfill();
        })(function() {
          var _k, _len2;
          if (err) {
            done(client);
            return next(err);
          }
          done();
          for (_k = 0, _len2 = records.length; _k < _len2; _k++) {
            item = records[_k];
            jobs.sched_effect(item.uuid, moment());
          }
          req.app.set('notify_modified_time', moment().format('x'));
          return res.json({
            succ: true,
            redirect: '/merch'
          });
        });
      };
    })(this));
  });

  router.post('/batch/disable', function(req, res, next) {
    var client, done, err, index, item, k, params, records, result, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['records'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    records = JSON.parse(req.body.records);
    if (records.length === 0) {
      return {
        succ: true,
        redirect: '/merch'
      };
    }
    params = [];
    where_clause = "uuid in (";
    for (index = _j = 0, _len1 = records.length; _j < _len1; index = ++_j) {
      item = records[index];
      where_clause += "$" + (index + 1);
      if (index < records.length - 1) {
        where_clause += ", ";
      }
      params.push(item.uuid);
    }
    where_clause += ")";
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1043
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch set disabled = true where " + where_clause, params, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1048
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.json({
            succ: true,
            redirect: '/merch'
          });
        });
      };
    })(this));
  });

  router.post('/batch/enable', function(req, res, next) {
    var client, done, err, index, item, k, params, records, result, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['records'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    records = JSON.parse(req.body.records);
    if (records.length === 0) {
      return {
        succ: true,
        redirect: '/merch'
      };
    }
    params = [];
    where_clause = "uuid in (";
    for (index = _j = 0, _len1 = records.length; _j < _len1; index = ++_j) {
      item = records[index];
      where_clause += "$" + (index + 1);
      if (index < records.length - 1) {
        where_clause += ", ";
      }
      params.push(item.uuid);
    }
    where_clause += ")";
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1075
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("update pay_merch set disabled = false where " + where_clause, params, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1080
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.json({
            succ: true,
            redirect: '/merch'
          });
        });
      };
    })(this));
  });

  router.post('/batch/delete', function(req, res, next) {
    var client, done, err, index, item, k, records, result, uuids, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['records'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    records = JSON.parse(req.body.records);
    uuids = "(";
    for (index = _j = 0, _len1 = records.length; _j < _len1; index = ++_j) {
      item = records[index];
      uuids += "'" + item.uuid + "'";
      if (index < records.length - 1) {
        uuids += ", ";
      }
    }
    uuids += ")";
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1103
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_merch where settl_merid in " + uuids + " or mapto_merid in " + uuids, __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1109
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length > 0) {
            done();
            return next(new Error("记录中存在正被其它商户引用的记录，在解除引用关系之前不允许删除"));
          }
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query("select * from pay_merch_ex where settl_merid in " + uuids + " or mapto_merid in " + uuids, __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 1119
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            if (result.rows.length > 0) {
              done();
              return next(new Error("记录中存在正被待复核表中的其它商户引用的记录，在解除引用关系之前不允许删除"));
            }
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("select * from pay_terms where merid in " + uuids, __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 1128
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              if (result.rows.length > 0) {
                done();
                return next(new Error("记录中存在正被终端引用的记录，在解除引用关系之前不允许删除"));
              }
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                });
                client.query("select * from pay_merch_ex where ref_uuid in " + uuids, __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 1137
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                if (result.rows.length > 0) {
                  done();
                  return next(new Error("记录中有被用户修改后尚未生效的记录，在新信息生效前不允许删除"));
                }
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                  });
                  client.query("insert into pay_merch_ex ( uuid,              inside,         chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, ref_serial,        ref_uuid, inputer,           input_time,     action ) ( select md5(random()::text || clock_timestamp()::text)::uuid::varchar, inside,            chnl,           merno, t20_fee,           trctl,          settl_merid,    mapto_merid, name,              contact,        telephone,      mobile, fax,               email,          address, unit_name,         unit_name_abbr, unit_english,     unit_english_abbr, unit_code,         unit_license,   unit_license_exp, unit_tax_code, unit_issuer,       unit_address,   unit_type,        unit_legal_name, unit_cred_type,    unit_cred_no,   unit_assets,      unit_scope, keys,              notes, serial,            uuid, $1,                CURRENT_TIMESTAMP, 3 from pay_merch where uuid in " + uuids + " )", [req.session.userinfo.uuid], __iced_deferrals.defer({
                    assign_fn: (function() {
                      return function() {
                        err = arguments[0];
                        return result = arguments[1];
                      };
                    })(),
                    lineno: 1170
                  }));
                  __iced_deferrals._fulfill();
                })(function() {
                  if (err) {
                    done(client);
                    return next(err);
                  }
                  done();
                  req.app.set('notify_modified_time', moment().format('x'));
                  return res.json({
                    succ: true,
                    redirect: '/merch'
                  });
                });
              });
            });
          });
        });
      };
    })(this));
  });

  router.post('/batch/delete_ex', function(req, res, next) {
    var client, done, err, index, item, k, records, ref_uuids, result, uuids, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _j, _len, _len1, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['records'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    records = JSON.parse(req.body.records);
    uuids = "(";
    for (index = _j = 0, _len1 = records.length; _j < _len1; index = ++_j) {
      item = records[index];
      uuids += "'" + item.uuid + "'";
      if (index < records.length - 1) {
        uuids += ", ";
      }
    }
    uuids += ")";
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1193
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select ref_uuid from pay_merch_ex where inputer = $1 and uuid in " + uuids, [req.session.userinfo.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1200
          }));
          __iced_deferrals._fulfill();
        })(function() {
          var _k, _len2, _ref1;
          if (err) {
            done(client);
            return next(err);
          }
          ref_uuids = "(";
          _ref1 = result.rows;
          for (index = _k = 0, _len2 = _ref1.length; _k < _len2; index = ++_k) {
            item = _ref1[index];
            ref_uuids += "'" + item.ref_uuid + "'";
            if (index < records.length - 1) {
              ref_uuids += ", ";
            }
          }
          ref_uuids += ")";
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
            });
            client.query('begin');
            __iced_deferrals._fulfill();
          })(function() {
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
              });
              client.query("delete from pay_merch_ex where checked = false and inputer = $1 and uuid in " + uuids, [req.session.userinfo.uuid], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 1216
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                });
                client.query("delete from pay_merch where shaded = true and inputer = $1 and uuid in " + ref_uuids, [req.session.userinfo.uuid], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 1223
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
                  });
                  client.query('commit');
                  __iced_deferrals._fulfill();
                })(function() {
                  done();
                  req.app.set('notify_modified_time', moment().format('x'));
                  return res.json({
                    succ: true,
                    redirect: '/merch'
                  });
                });
              });
            });
          });
        });
      };
    })(this));
  });

  router.get('/import', function(req, res, next) {
    res.locals.breadcrumbs.push({
      'title': '导入商户信息'
    });
    return res.render('merch/import', {
      record: {}
    });
  });

  uploader = multer({
    dest: settings.upload_path
  });

  router.post('/import', uploader.single('attach_file'), function(req, res, next) {
    var dest_path, err, k, magic, result, today, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    _ref = ['inside', 'chnl'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    if (!req.file) {
      return next(new Error("请求缺少上传文件."));
    }
    magic = new mmm.Magic(mmm.MAGIC_MIME_TYPE);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        magic.detectFile(req.file.path, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              return result = arguments[1];
            };
          })(),
          lineno: 1249
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          fs.unlink(req.file.path);
          return next(new Error('不能检测文件类型，导入失败'));
        }
        if (result !== 'text/plain') {
          fs.unlink(req.file.path);
          return next(new Error('上传的文件格式非文本文件，无效'));
        }
        if (req.body.inside === 'true') {
          dest_path = "" + settings.upload_path + "/merch/" + req.body.chnl + "/inner";
        } else {
          dest_path = "" + settings.upload_path + "/merch/" + req.body.chnl + "/outer";
        }
        mkdirp.sync(dest_path);
        today = moment().format('YYYY-MM-DD');
        fs.rename(req.file.path, "" + dest_path + "/" + today + ".txt");
        return res.redirect('/merch');
      };
    })(this));
  });

  router.get('/export', function(req, res, next) {
    res.locals.breadcrumbs.push({
      'title': '导出商户信息'
    });
    return res.render('merch/export', {
      record: {}
    });
  });

  router.post('/export', function(req, res, next) {
    return res.redirect('/merch');
  });

  router.all('/ajax/mapto_merids', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['chnl'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1283
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select uuid, merno, name, shaded from pay_merch where inside = false and chnl = $1 and disabled = false", [req.body.chnl], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1290
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          return res.json({
            succ: true,
            records: result.rows
          });
        });
      };
    })(this));
  });

  router.post('/ajax/trctl_info', function(req, res, next) {
    var client, done, err, k, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['trctl_uuid'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 1302
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/Users/wuxiaohu/lucky-byte/luckpay-web/coffee/routes/merch.coffee"
          });
          client.query("select * from pay_trctl_t where uuid = $1", [req.body.trctl_uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 1307
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          record = result.rows[0];
          return res.json({
            succ: true,
            record: record
          });
        });
      };
    })(this));
  });

}).call(this);
